Categories
MongoDB

Node.js Basics — Creating and Deploying Packages

Spread the love

Node.js is a popular runtime platform to create programs that run on it.

It lets us run JavaScript outside the browser.

In this article, we’ll look at how to start using Node.js to create programs.

Creating NPM Packages

We can create our own NPM packages to do that, we run npm add user so we can log into NPM to create our package.

Once we typed in the command, we’ll have to enter a username, password, and email address for our account to create an account on NPM.

The email wil be public.

Then we run npm init to create our package’s package.json file.

Once we answered all the questions, we should get something like:

{
  "name": "npm-example",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo "Error: no test specified" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

Once we’re done, we can run npm publish to publish our package.

Then once we published our package, we can run:

npm install npm-example

to install our package.

To update the version of our package, we run npm version patch .

Then we can run npm publish to publish the package with the later version.

To keep some files from being published in a package, we can create a .npmignore file which follows the same rules as the .gitignore file.

Conclusion

We can create NPM packages easily with npm .

All we have to do is enter some package data and publish the package.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *